<?php

namespace app\model;

use think\Db;

class AdminInfo extends LoginCommon
{
    private static $obj = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->db_name = 'admin_info';
    }

    /**
     * 类入口
     * @return AdminInfo|null
     */
    public static function getInstance()
    {
        if (is_null(self::$obj))
            self::$obj = new self();
        return self::$obj;
    }

    /**
     * 检查是否是超级管理员 1-是
     * @param $int_admin_id
     * @return int
     */
    public function checkIsSuper($int_admin_id)
    {
        return (int)$this->toValue(['id' => $int_admin_id], 'is_super');
    }

    /**
     * 检查登录账号是否存在
     * @param $str_login_account
     * @return bool|int
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    /*    public function checkIsSetAccount($str_login_account)
        {
            $arr_info = $this->toFind(['login_account' => $str_login_account], 'id as admin_id');
            if (isset($arr_info['admin_id'])) {
                return (int)$arr_info['admin_id'];
            } else {
                return false;
            }
        }*/

    /**
     * 获取账户信息列表
     * @param $arr_where
     * @param $str_field
     * @param $int_first_row
     * @param $int_list_rows
     * @param $str_order
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getAccountList($arr_where, $str_field, $int_first_row, $int_list_rows, $str_order)
    {
        return Db::name($this->db_name)
            ->alias('fa')
            ->where($arr_where)
            ->join(AdminGroup::getInstance()->db_name . ' fg', 'fa.group_id=fg.id', 'LEFT')
            ->field($str_field)
            ->limit($int_first_row, $int_list_rows)
            ->order($str_order)
            ->select();
    }
}